package com.ylbh.modules.outerchain.service.impl;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.ylbh.common.utils.PageDTO;
import com.ylbh.common.utils.ShiroUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ylbh.common.utils.PageUtils;

import com.ylbh.modules.outerchain.mapper.ShoppingOuterChainMapper;
import com.ylbh.modules.outerchain.entity.ShoppingOuterChain;
import com.ylbh.modules.outerchain.service.ShoppingOuterChainService;

import java.util.Date;
import java.util.List;


@Service("shoppingOuterChainService")
public class ShoppingOuterChainServiceImpl extends ServiceImpl<ShoppingOuterChainMapper, ShoppingOuterChain> implements ShoppingOuterChainService {

    @Autowired
    private ShoppingOuterChainMapper shoppingOuterChainMapper;

    /**
     * 外链管理列表
     * @param dto
     * @return
     */
    @Override
    public PageUtils queryOuterChainList(PageDTO dto) {
        Page<Integer> page = new Page<>(dto.getPage(), dto.getLimit());
        List<ShoppingOuterChain> list = shoppingOuterChainMapper.selectOuterChainList(dto.getKeywords(), page);
        return new PageUtils(new Page<ShoppingOuterChain>().setRecords(list).setTotal(page.getTotal()));
    }

    /**
     * 外链详情
     * @param id
     * @return
     */
    @Override
    public ShoppingOuterChain getOuterChainById(Long id) {
        return shoppingOuterChainMapper.selectById(id);
    }

    /**
     * 修改外链
     * @param shoppingOuterChain
     */
    @Override
    public void modifyOuterChainById(ShoppingOuterChain shoppingOuterChain) {
        shoppingOuterChain.setUpdateTime(new Date());
        shoppingOuterChain.setCreateUserId(ShiroUtils.getUserId().intValue());
        shoppingOuterChainMapper.updateById(shoppingOuterChain);
    }

    /**
     * 增加外链
     * @param shoppingOuterChain
     */
    @Override
    public void addOuterChain(ShoppingOuterChain shoppingOuterChain) {
        shoppingOuterChain.setCreateTime(new Date());
        shoppingOuterChain.setCreateUserId(ShiroUtils.getUserId().intValue());
        shoppingOuterChainMapper.insert(shoppingOuterChain);
    }

    /**
     * 删除外链
     * @param ids
     */
    @Override
    public void removeOuterChain(List<Long> ids) {
        shoppingOuterChainMapper.deleteOuterChain(ids, new Date(), ShiroUtils.getUserId());
    }

    /**
     * 修改外链启用状态
     * @param id
     * @param isEnable
     */
    @Override
    public void modifyIsEnableById(Long id, Integer isEnable) {
        shoppingOuterChainMapper.updateIsEnableById(id, isEnable);
    }

    /**
     * 外链下级列表
     * @param dto
     * @return
     */
    @Override
    public PageUtils queryOuterChainSubordinateList(PageDTO dto) {
        Page<Integer> page = new Page<>(dto.getPage(), dto.getLimit());
        List<ShoppingOuterChain> list = shoppingOuterChainMapper.queryOuterChainSubordinateList(dto.getKeywords(), page);
        return new PageUtils(new Page<ShoppingOuterChain>().setRecords(list).setTotal(page.getTotal()));
    }

    /**
     * 活动下拉
     * @return
     */
    @Override
    public List<ShoppingOuterChain> queryActivityOuterChainList() {
        return shoppingOuterChainMapper.selectActivityOuterChainList();
    }
}
